package logic

import (
	"context"
	"product_zc/models/mysql"

	"product_zc/productRpc/internal/svc"
	"product_zc/productRpc/productRpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type DelProductLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewDelProductLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DelProductLogic {
	return &DelProductLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *DelProductLogic) DelProduct(in *productRpc.DelProductRequest) (*productRpc.DelProductResponse, error) {
	// todo: add your logic here and delete this line

	product := mysql.Product{}
	mysql.DB.Where("user_id=? and id=?", in.UserId, in.Id).
		Find(&product)

	mysql.DB.Delete(&product)

	return &productRpc.DelProductResponse{}, nil
}
